// 商品管理脚本
$(function() {
	$("#searchid").linkbutton({
				text : '查询',
				iconCls : 'icon-search'
			});
	$('#messagegrid').datagrid({
		title : '您所在的位置：论坛管理模块&nbsp;&nbsp;--&gt;&gt;&nbsp;&nbsp;论坛管理',
		idField : 'id',
		width : 1000,
		height : 450,
		nowrap : false,
		striped : true,
		collapsible : false,
		url : '../goods/goods_searchTribune.shtml?flag=manageT',
		frozenColumns : [[{
					field : 'ck',
					title : '选择',
					checkbox : true
				}]],
		columns : [[{
					title : '基本信息',
					colspan : 5
				}, {
					field : 'opt',
					title : '操作',
					width : 100,
					align : 'center',
					rowspan : 2,
					formatter : function(value, rec) {
					if (rec.id == undefined)
							return null;
						else
							return '<span style="color:red"><span onclick=onView("'
									+ rec.id
									+ '")><font style="cursor:pointer;color:blue;">查看</font></span></span>';
					}
				}], [{
					field : 'title',
					title : '标题',
					mapping : 'title',
					align : 'center',
					width : 450
				}, {
					field : 'authorName',
					title : '发帖人',
					width : 95,
					mapping : 'authorName',
					align : 'center' 
				},{
					field : 'isMarrow',
					title : '是否是精华帖',
					width : 84,
					formatter : function(value, rec) {
						   if(value=='1')return '<font color="red">是</font>';
						   else return '否';
					},
					mapping : 'authorName',
					align : 'center' 
				},{
					field : 'isTop',
					title : '是否置顶',
					width : 84,
					formatter : function(value, rec) {
						   if(value=='1')return '<font color="red">是</font>';
						   else return '否';
					},
					mapping : 'authorName',
					align : 'center' 
				},{
					field : 'createTimeString',
					title : '发帖时间',
					align : 'center',
					mapping : 'createTimeString',
					width : 120,
					sortable : true
				}
		]],
		pagination : true,
		rownumbers : true,
		queryParams : {
			startTime : '',
			endTime : ''
		},
		toolbar : [/*{
					id : 'btnadd',
					text : '发帖',
					iconCls : 'icon-add',
					handler : function() {
						$(this).attr("href", '../tribune/tribune_modifyTribunePage.shtml?menuCls=313&id=0');
					}
				}, '-', */{
					id : 'btnsave',
					text : '删帖',
					iconCls : 'icon-remove',
					handler : function() {
						var records = $('#messagegrid').datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要删除的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {
								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						if (confirm("确定删除所选信息吗?")) {
						var url1 = "../tribune/tribune_deletetribune.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids + "&type=1",
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});
						}
					}
				},'-',{
					id : 'btnadd',
					text : '标记为精华帖',
					iconCls : 'icon-ok',
					handler : function() {
						var records = $('#messagegrid')
								.datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要标记的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {
								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						if (confirm("确定标记所选记录吗?")) {
						var url1 = "../tribune/tribune_changeIsMarrow.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids + "&isMarrow=1",
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});
						}
					}
				},'-',{
					id : 'btnadd',
					text : '撤销标记',
					iconCls : 'icon-undo',
					handler : function() {
						var records = $('#messagegrid')
								.datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要撤销标记的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {
								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						if (confirm("确定撤销标记所选记录吗?")) {
						var url1 = "../tribune/tribune_changeIsMarrow.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids + "&isMarrow=2",
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});
						}
					}
				},'-',{
					id : 'btnadd',
					text : '置顶',
					iconCls : 'icon-ok',
					handler : function() {
						var records = $('#messagegrid')
								.datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要置顶的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {
								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						if (confirm("确定置顶所选记录吗?")) {
						var url1 = "../tribune/tribune_toTop.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids+"&topType=1" ,
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});
						}
					}
				},'-',{
					id : 'btnadd',
					text : '撤销置顶',
					iconCls : 'icon-undo',
					handler : function() {
						var records = $('#messagegrid')
								.datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要撤销置顶的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {
								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						if (confirm("确定撤销置顶所选记录吗?")) {
						var url1 = "../tribune/tribune_toTop.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids+"&topType=0",
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});
						}
					}
				},'-',{
					id : 'btnclose',
					text : '  &nbsp;关  闭',
					iconCls : 'icon-cancel',
					handler : function() {
						window.self.close();
					}
				}
				]
		}
	);
	 $(".searchcenter").keydown(function(){
	     if(event.keyCode==13)
         {
           onSearch();
         }
	    });
});

function onSearch() {
    //var category= $("#category").combobox("getValue");
	var queryParams = $('#messagegrid').datagrid("options").queryParams;
	queryParams.title = $("#title").val();
	queryParams.flag='manageT';
	//queryParams.category =category;
	$('#messagegrid').datagrid("reload");
}

function ondelete(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	if (confirm("确定标记此条记录吗?")) {
		var url1 = "../tribune/tribune_deletetribune.shtml";
		$.ajax({
				url : url1,
				data : "id=" + id,
				success : function(msg) {
					var obj = eval('(' + msg + ')');
					var result = obj[0]["message"];
					alert(result);
					$('#messagegrid').datagrid("reload");
				}
			});
	}
}
function toTop(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	if (confirm("确定置顶此条记录吗?")) {
		var topType = document.getElementById("aud_"+id).value;
		var url1 = "../tribune/tribune_toTop.shtml";
		$.ajax({
				url : url1,
				data : "idString=" + id+"&topType="+topType ,
				success : function(msg) {
					var obj = eval('(' + msg + ')');
					var result = obj[0]["message"];
					alert(result);
					$('#messagegrid').datagrid("reload");
				}
			});
	}
}
function onView(id) {
	if (id == "undefined") {
		alert("此条记录已被删除");
		return;
	} 
	window.open('../tribune/tribune_searchById.shtml?id='+id);
}
